//
//  NSArray+Extend.m
//  etionMisc
//
//  Created by wjxfhxy on 14-6-5.
//  Copyright (c) 2014年 GuangZhouXuanWu. All rights reserved.
//

#import "NSArrayExtend.h"

@implementation NSArray (FetchArrayObjectPorpertyValue)

-(instancetype)fetchArrayObjectPorpertyValueWithPorperty:(NSString*)porperty
{
    NSMutableArray *ar = [[NSMutableArray new] autorelease_mm];
    for(id i in self)
    {
        [ar addObject:[i valueForKey:porperty]];
    }
    return ar;
}

-(instancetype)fetchArrayObjectPorpertyValueWithPorpertyNotNil:(NSString*)porperty
{
    NSMutableArray *ar = [[NSMutableArray new] autorelease_mm];
    for(id i in self)
    {
        id value = [i valueForKey:porperty];
        if (value != nil)
        {
            [ar addObject:value];
        }
    }
    return ar;
}

-(NSArray*)fetchArrayObjectDictionaryValueWithKey:(NSString*)key
{
    NSMutableArray *ar = [[NSMutableArray new] autorelease_mm];
    for(NSDictionary *dic in self)
    {
        [ar addObject:dic[key]];
    }
    return ar;
}

@end

@implementation NSArray (CNumberArrayToNSStringArray)

-(NSArray*)cnumberArrayToNSStringArray
{
    NSMutableArray *ar = [[NSMutableArray new] autorelease_mm];
    for(XMSNumber *n in self)
    {
        [ar addObject:[n toNSString]];
    }
    return ar;
}

@end

/*
@implementation NSArray (FilterArrayObjects)

-(void)compareFirstArray:(NSArray*)firstArray porpertyValue:(id(^)(id firstArrayObj))firstArrayObj andSecondArray:(NSArray*)secondArray porpertyValue:(id(^)(id secondArrayObj))secondArrayObj result:(void(^)(NSArray *commonArray,NSArray* diffArray))result
{
    NSMutableArray *commonArray = [NSMutableArray new];
    NSMutableArray *diffArray = [NSMutableArray new];
    for(id i in firstArray)
    {
        BOOL b = NO;
        for(id j in secondArray)
        {
            if([firstArrayObj(i) isEqual:secondArrayObj(j)] == YES)
            {
                b = YES;
                [commonArray addObject:i];
                break;
            }
        }
        if(b == NO)
            [diffArray addObject:i];
    }
}

@end
*/